import java.util.Random;
public class Main {

    /**
     * 测试使用q运行opCount个enQueue和deQueue操作所需时间，单位：秒
     * @param q
     * @param opCount
     * @return
     */
    private static double testQueue(Queue<Integer> q, int opCount){
        long startTime = System.nanoTime();

        Random random = new Random();
        for (int i = 0; i < opCount; i++) {
            q.enQueue(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < opCount; i++) {
            q.deQueue();
        }
        long endTime = System.nanoTime();

        return (endTime - startTime) / 1000000000.0;     //将纳秒转换为秒
    }
    public static void main(String[] args) {
        int opCount = 100000;

        LinkedListQueue<Integer> linkedListQueue = new LinkedListQueue<>();
        double time3 = testQueue(linkedListQueue, opCount);
        System.out.println("LinkedListQueue, time: "+time3+" s");

        LoopQueue<Integer> loopQueue = new LoopQueue<>();
        double time2 = testQueue(loopQueue, opCount);
        System.out.println("LoopQueue, time: "+time2+" s");

        ArrayQueue<Integer> arrayQueue = new ArrayQueue<>();
        double time1 = testQueue(arrayQueue, opCount);
        System.out.println("ArrayQueue, time: "+time1+" s");
    }
}
